package com.yihu.wlyy.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.yihu.wlyy.entity.patient.PatientHealthRecordDiet;

import java.util.Date;

public interface PatientHealthRecordDietDao extends PagingAndSortingRepository<PatientHealthRecordDiet, Long>, JpaSpecificationExecutor<PatientHealthRecordDiet> {

	// 查询患者标识健康记录
	@Query("select a from PatientHealthRecordDiet a where a.patient = ?1 and a.del = '1'")
	Iterable<PatientHealthRecordDiet> findByPatient(String patient);
	
	// 查询最近的健康记录
	@Query("SELECT a FROM PatientHealthRecordDiet a WHERE a.patient = ?1 and a.del = '1' ORDER BY a.czrq DESC")
	Page<PatientHealthRecordDiet> findRecentByPatient(String patient, Pageable pageRequest);

	@Query("SELECT a FROM PatientHealthRecordDiet a WHERE a.patient = ?1 and a.recordDate >= ?2 and a.recordDate <= ?3 and a.del = '1' ORDER BY a.recordDate DESC")
	Page<PatientHealthRecordDiet> findDietByPatient(String patient, Date start, Date end, Pageable pageRequest);
}
